package com.ourteam.system.api;

import org.apache.commons.lang.ArrayUtils;

import com.ourteam.frame.web.AbstractTreeBuilder;
import com.ourteam.frame.web.TreeViewNodeBean;
import com.ourteam.system.domain.SystemAction;
import com.ourteam.system.domain.SystemModule;

public class SystemRolePurViewModuleTreeBuilder extends AbstractTreeBuilder {

	private SystemModule[] roleModules = new SystemModule[0];
	
	private SystemAction[] roleActions = new SystemAction[0];

	public SystemRolePurViewModuleTreeBuilder(SystemModule[] roleModules,SystemAction[] roleActions) {
		super();
		this.roleModules = roleModules;
		this.roleActions = roleActions;
	}

	@Override
	protected String getTreeConfigFile() {
		return "classpath:ui/system/sys_role_purview.tree";
	}

	protected TreeViewNodeBean configTreeViewNodeProperties(Object obj, TreeViewNodeBean treeViewNodeBean) {

		if (obj instanceof SystemModule) {

			SystemModule systemModule = (SystemModule) obj;

			treeViewNodeBean.getState().setChecked(ArrayUtils.contains(roleModules, systemModule));
			
			treeViewNodeBean.setIcon(systemModule.getModuleIcon());

		}
		
		if(obj instanceof SystemAction) {
			
			SystemAction systemAction = (SystemAction) obj;

			treeViewNodeBean.getState().setChecked(ArrayUtils.contains(roleActions, systemAction));

			treeViewNodeBean.setIcon("far fa-cog");
			
		}

		return treeViewNodeBean;
	}

}
